package nc.ui.arap.view;

import nc.ui.pub.ButtonObject;
import nc.ui.pub.msg.SwingWorker;
import nc.vo.pub.BusinessException;

public class ActionSwingWorker<T> extends SwingWorker {
	
	private Controler<T> controler;
	
	private ButtonObject buttonObject;
	
	private ViewContext<T> context;
	
	public ActionSwingWorker(Controler<T> controler, ButtonObject buttonObject, ViewContext<T> context) {
		this.controler = controler;
		this.buttonObject = buttonObject;
		this.context = context;
	}

	@Override
	public Object construct() {
		try {
			controler.getActionMap().get(buttonObject.getCode()).handle(context);
		} catch (BusinessException e) {
			context.showErrorMessage(e.getMessage());
		}
		context.releaseUI();
		return null;
	}

}
